﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MISAPP.MISInterface;

public partial class View_CIB_CIB003_1 : ViewMatrix
{
    string category = string.Empty;
    string YM = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {

        criteriaList = new string[] { "Criteria", "ExclusiveOfAccount", "Money", "Sign" };
        serviceName = "MISAPP.Classify.Service.Service_CIB003";
        btn2Excel.PageParameter = "method=GetSummaryData2&xls=CIB003&service=Service_CIB003";
        category = Request.QueryString["C"] as string;
        if (category.Equals("1"))
        {
            btn2Excel.PageParameter = "method=GetSummaryData&xls=CIB003&service=Service_CIB003";
        }
        if (category.Equals("3"))
        {
            btn2Excel.PageParameter = "method=GetSummaryData3&xls=CIB003&service=Service_CIB003";
        }

        getYM();
        if (!IsPostBack)
        {
            GetData();
        }
    }

    protected string getMoney()
    {
        return Session["Money"] as string;
    }

    private void GetData()
    {
        string sevMethod = string.Empty;
        sevMethod = category.Equals("1") ? "GetSummaryData" : "GetSummaryData2";
        if (category.Equals("3"))
        {
            sevMethod = "GetSummaryData3";
        }

        System.Data.DataTable dt = GetDataFromSerevice(sevMethod);
        CLB_Summary.PageSize = GetGridViewPageSize();
        CLB_Summary.SetData(dt, new string[] { });
    }

    protected void previous_click(object sender, EventArgs e)
    {
        Utility.SessionClear();
    }

    protected void btn2Excel_Click(object sender, EventArgs e)
    {
        FillToSession();
    }

    protected void CLB_Summary_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GetData();
    }

    protected void CLB_Summary_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (category.Equals("1"))
        { categoryOne(e); }
        if (category.Equals("2"))
        {
            categoryTwo(e);
        }

    }

    protected void categoryTwo(GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[0].Text.IndexOf('_') < 0)
            { return; }
            string urlString, lnac_id;
            urlString = "../view/CIB/CIB003_2.aspx?LNAC_ID={0}&YYYYMM={1}&ACCOUNTNO={2}&Money={3}";
            HyperLink link = new HyperLink();
            lnac_id = e.Row.Cells[0].Text.Substring(0, e.Row.Cells[0].Text.IndexOf('_'));
            //lnac_id = Utility.GetDeEncrypt(lnac_id);
            link.Text = e.Row.Cells[0].Text;
            link.NavigateUrl = string.Format(urlString
                , lnac_id
                , YM
                , string.Empty
                , getMoney()
                );
            e.Row.Cells[0].Controls.Add(link);
        }
    }

    protected void categoryOne(GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[6].Text.Equals("1"))
            {
                e.Row.CssClass = "diff";
            }
            //0 2 3
            string urlString = "../view/CIB/CIB003_2.aspx?LNAC_ID={0}&YYYYMM={1}&ACCOUNTNO={2}&Money={3}";
            HyperLink link = new HyperLink();
            link.Text = e.Row.Cells[0].Text;
            link.NavigateUrl = string.Format(urlString
                , e.Row.Cells[0].Text
                , e.Row.Cells[2].Text
                , e.Row.Cells[3].Text
                , getMoney()
                );
            e.Row.Cells[0].Controls.Add(link);
        }
    }

    protected void CLB_Summary_Sorting(object sender, GridViewSortEventArgs e)
    {
        GetData();

    }

    protected void getYM()
    {
        List<iSelectList> criteriaList = Session["Criteria"] as List<iSelectList>;
        foreach (iSelectList SL in criteriaList)
        {
            if (SL.GetField().Equals("YYYYMM"))
            {
                YM = string.Join("_", SL.GetListArray());
            }
        }
    }


}
